<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>libdill</title>
  <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>

<h1>libdill: Structured Concurrency for C</h1>

<ul id='toplist'>
<li><a href="index.html">Home</a></li>
<li><a href="download.html">Download</a></li>
<li><a href="documentation.html">Documentation</a></li>
<li><a href="tutorial.html">Tutorials</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
<h1 id="name">NAME</h1>
<p>chmake_mem - creates a channel</p>
<h1 id="synopsis">SYNOPSIS</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="pp">#include </span><span class="im">&lt;libdill.h&gt;</span>

<span class="dt">int</span> chmake_mem(
    <span class="kw">struct</span> chstorage* mem,
    <span class="dt">int</span> chv[<span class="dv">2</span>]);</code></pre></div>
<h1 id="description">DESCRIPTION</h1>
<p>Creates a bidirectional channel. In case of success handles to the both sides of the channel will be returned in <strong>chv</strong> parameter.</p>
<p>A channel is a synchronization primitive, not a container. It doesn't store any items.</p>
<p>This function allows to avoid one dynamic memory allocation by storing the object in user-supplied memory. Unless you are hyper-optimizing use <strong>chmake</strong> instead.</p>
<p><strong>mem</strong>: The structure to store the newly created object in. It must not be deallocated before the object is closed.</p>
<p><strong>chv</strong>: Out parameter. Two handles to the opposite ends of the channel.</p>
<h1 id="return-value">RETURN VALUE</h1>
<p>In case of success the function returns 0. In case of error it returns -1 and sets <strong>errno</strong> to one of the values below.</p>
<h1 id="errors">ERRORS</h1>
<ul>
<li><strong>EMFILE</strong>: The maximum number of file descriptors in the process are already open.</li>
<li><strong>ENFILE</strong>: The maximum number of file descriptors in the system are already open.</li>
<li><strong>ENOMEM</strong>: Not enough memory.</li>
</ul>
<h1 id="example">EXAMPLE</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int</span> ch[<span class="dv">2</span>];
<span class="dt">int</span> rc = chmake(ch);
<span class="cf">if</span>(rc == <span class="dv">-1</span>) {
    perror(<span class="st">&quot;Cannot create channel&quot;</span>);
    exit(<span class="dv">1</span>);
}</code></pre></div>
<h1 id="see-also">SEE ALSO</h1>
<p><strong>chdone</strong>(3) <strong>chmake</strong>(3) <strong>choose</strong>(3) <strong>chrecv</strong>(3) <strong>chsend</strong>(3) <strong>hclose</strong>(3)</p>
</body>
